import { loginApi } from "../../api/user";
import { getToken, setToken } from "../../utils/storage"

export default {
  namespaced: true, // 开启命名空间，让模块独立
  state: () => ({
    token: getToken('token')
  }),
  getters: {

  },
  mutations: {
    getToken(state, data) {
      state.token = data
      setToken('token',data)
    }
  },
  actions: {
    async getTokenAsync({ commit },val) {
      const {
        data
      } = await loginApi(val);
      // console.log(data);
      commit('getToken', data.token)
    },
  },
}